package Draw;

import java.io.*;
import java.util.Vector;

public class Recorder {
    private static int kill=0;
    private static Vector<KlmTank> klm=null;
    private static BufferedWriter bw=null;
    private static BufferedReader br=null;
    public static void setklm(Vector<KlmTank> klmTankVector){
        Recorder.klm=klmTankVector;
    }

    private static String Pathname="d:\\xx.txt";

    public static String getPathname() {
        return Pathname;
    }

    public static int getKill() {
        return kill;
    }
    private static Vector<Node> nodes=new Vector<>();
    public static Vector<Node> getNodes()  {
       try {
           br=new BufferedReader(new FileReader(Pathname));
           kill=Integer.parseInt(br.readLine());
           String str="";
           while ((str=br.readLine())!=null){
               String[] strings=str.split(" ");
               Node node=new Node(Integer.parseInt(strings[0]),Integer.parseInt(strings[1]),Integer.parseInt(strings[2]));
               nodes.add(node);
           }

       }catch (IOException e){
           e.printStackTrace();
       }finally {
           try {
               if(br!=null) {
                   br.close();
               }
           }catch (IOException e){
               e.printStackTrace();
           }
       }
        return nodes;
    }

    public static void setKill(int kill) {
        Recorder.kill = kill;
    }
    public static void AddKill(){
        Recorder.kill++;
    }
    public static void Bw() throws IOException {
        try {
            bw=new BufferedWriter(new FileWriter(Pathname));
            bw.write(kill+"\r\n");
            for (int i = 0; i < klm.size(); i++) {
                KlmTank klmTank=klm.get(i);
                if(klmTank.loop){
                    String record=klmTank.getX()+" "+klmTank.getY()+" "+klmTank.getDirection();
                    bw.write(record+"\r\n");

                }
            }
        } catch (IOException e) {
           e.printStackTrace();
        }finally {
            try {
                if (bw!=null){
                bw.close();}
            }catch (IOException e){
                e.printStackTrace();
            }
        }
    }
}
